package td.pt.event;

import td.domain.Category;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.HasHandlers;
import com.google.gwt.event.shared.HandlerRegistration;

public class CreateTopicEvent extends
		GwtEvent<CreateTopicEvent.CreateTopicHandler> {

	public static Type<CreateTopicHandler> TYPE = new Type<CreateTopicHandler>();

	public interface CreateTopicHandler extends EventHandler {
		void onCreateTopic(CreateTopicEvent event);
	}

	public interface CreateTopicHasHandlers extends HasHandlers {
		HandlerRegistration addCreateTopicHandler(CreateTopicHandler handler);
	}

	private HasHandlers source;
	private Category initialCategory;

	public CreateTopicEvent(HasHandlers source, Category initialCategory) {
		this.initialCategory = initialCategory;
		this.source = source;
	}
	
	/**
	 * @return the source
	 */
	public HasHandlers getSource() {
		return source;
	}

	/**
	 * @return the initialCategory
	 */
	public Category getInitialCategory() {
		return initialCategory;
	}

	@Override
	protected void dispatch(CreateTopicHandler handler) {
		handler.onCreateTopic(this);
	}

	@Override
	public Type<CreateTopicHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<CreateTopicHandler> getType() {
		return TYPE;
	}

	public static void fire(HasHandlers source, Category initialCategory) {
		source.fireEvent(new CreateTopicEvent(source, initialCategory));
	}
}
